data SEGMENT
    s db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
data ends

;A B C 控制端口地址
PORTA EQU 0600h
PORTB EQU 0602h
PORTC EQU 0604h
PORTCN EQU 0606h

code SEGMENT 
assume cs:code, ds:data
start:
    mov ax,data
    mov ds,ax

    mov dx,PORTCN
    mov al, 81h
    out dx,al

waitk:
    mov dx, PORTA
    mov al,0
    out dx,al

    mov dx,PORTC
    in al,dx

    cmp al,1111b
    jz waitk
    
    mov bl,0
    mov bh,11111110b
    mov cx,4
fndrow:
    mov dx,PORTA
    mov al,bh
    out dx,al

    rol bh,1;ѭ������1λ
    mov dx,PORTC
    in al,dx ;��c��
    cmp al,1111b;�ж��Ƿ�ȫΪ1 ȫΪ1û�бպ�0000
    jne fndcol; ���к�
    add bl,4;��һ�м��ų�ֵ��cmpΪ0������һ�в��ǣ����Ի��У�������0-15
    loop fndrow

fndcol: ;���кţ������al������һ���ҵ�����Ч���У�1���λ��0����
    ror al,1 ;ѭ������ û�н�λ�����ҵ���
    jnc right 
    inc bl
    jmp fndcol
    

right:;��� ������bl��
    mov al,bl
    mov bx,0
    mov bl,al
    mov dl,ds:[bx] 
    mov ah,02
    int 21h

    mov dx,3
delay2:;ȥ����
    mov cx,0
	call delay
	sub dx,1;dec
	cmp dx,0;��仰����û��
	jnz delay2  
	
    jmp waitk ;�����ȴ����룬��������
    
    
delay:
	loop delay
	ret    
code ENDS
END start
